using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace ICP_MS.Plugin.Advance;

public class FormVersion : Form
{
	private IContainer components = null;

	private FlowLayoutPanel flowLayoutPanel1;

	private Button btnRefresh;

	private GroupBox groupBox2;

	private TextBox txtDetector;

	private Label label5;

	private GroupBox groupBox1;

	private TextBox txtSerial1;

	private Label label4;

	private TextBox txtSerial2;

	private Label label2;

	public FormVersion()
	{
		InitializeComponent();
	}

	private void GetVersion(uint[] version, string name)
	{
		uint t_version = version[0] + (version[1] << 8) + (version[2] << 16) + (version[3] << 24);
		string[] s_version = new string[4] { "0", "0", "0", "0" };
		s_version[0] = (t_version % 1000).ToString();
		s_version[1] = (t_version / 1000 % 1000).ToString();
		s_version[2] = (t_version / 1000000).ToString();
		Label lbl1 = new Label();
		lbl1.Size = new Size(240, 30);
		lbl1.Text = name + "V" + s_version[2] + "." + s_version[1] + "." + s_version[0];
		flowLayoutPanel1.Controls.Add(lbl1);
	}

	private void GetDetectorVersion(string version, string name)
	{
		Label lbl1 = new Label();
		lbl1.Size = new Size(240, 30);
		lbl1.Text = name + "V" + version;
		flowLayoutPanel1.Controls.Add(lbl1);
	}

	private void GetVersion1(uint[] version, string name)
	{
		uint t_version = version[3] + (version[2] << 8) + (version[1] << 16) + (version[0] << 24);
		string[] s_version = new string[4] { "0", "0", "0", "0" };
		s_version[0] = (t_version % 1000).ToString();
		s_version[1] = (t_version / 1000 % 1000).ToString();
		s_version[2] = (t_version / 100000000).ToString();
		Label lbl1 = new Label();
		lbl1.Size = new Size(240, 30);
		lbl1.Text = name + "V" + s_version[2] + "." + s_version[1] + "." + s_version[0];
		flowLayoutPanel1.Controls.Add(lbl1);
	}

	private void FormVersion_Load(object sender, EventArgs e)
	{
		ApplyResources();
		Timer timer = new Timer();
		timer.Interval = 1000;
		timer.Tick += Timer_Tick;
		timer.Start();
	}

	private void ApplyResources()
	{
		groupBox1.Text = Lang.Txt("ADD.Version.CollisionCell");
		groupBox2.Text = Lang.Txt("ADD.Version.Multiplier");
		label2.Text = Lang.Txt("ADD.Version.MolecularPump1Number");
		label4.Text = Lang.Txt("ADD.Version.MolecularPump2Number");
		label5.Text = Lang.Txt("ADD.Version.MultiplierNumber");
		btnRefresh.Text = Lang.Txt("ADD.Version.Refresh");
	}

	private void Timer_Tick(object sender, EventArgs e)
	{
		flowLayoutPanel1.Controls.Clear();
		try
		{
			GetVersion(Vacuum.vacumm.ReadVacuumVersion, Lang.Txt("ADD.Version.Vacuum"));
			GetVersion(PlatManager.plat.ReadVersion, Lang.Txt("ADD.Version.PlatAndPump"));
			GetVersion(LensManager.x2lens.ReadVersion, Lang.Txt("ADD.Version.Lens"));
			GetVersion(PlasmaManager.plasma.ReadVersion, "Plasma：");
			GetVersion(PlasmaManager.plasma.gasReadVersion, "MFC：");
			GetVersion(PowerManager.powerStatus.ReadVersion, Lang.Txt("ADD.Version.TotalPower"));
			GetVersion(QuadMonitor.quad.ReadVersion, Lang.Txt("ADD.Version.Quadruple"));
			GetDetectorVersion(Detector.Instance.ReadVersion, Lang.Txt("ADD.Version.DataBoard"));
			GetVersion1(PlasmaManager.plasma.ColReadVersion, Lang.Txt("ADD.Version.CollisionCell"));
		}
		catch (Exception)
		{
		}
	}

	private void btnRefresh_Click(object sender, EventArgs e)
	{
		Vacuum.Instance.SendVersion();
		Plasma.Instance.SendMFCVersion();
		Plasma.Instance.SendPlasmaVersion();
		Plasma.Instance.SendplatVersion();
		LensManager.Instance.SendVersion();
		Plasma.Instance.SendCollisionVersion();
		QuadMonitor.Instance.SendVersion();
		PowerManager.Instance.SendVersion();
		Detector.Instance.msDetectorRF.SendVersion();
		try
		{
			SerialConfig serialConfig = new SerialConfig();
			string SerialConfigPath = Application.StartupPath + "//iMassConfig//SerialConfig.xml";
			if (!XMLFile.Open(SerialConfigPath, ref serialConfig))
			{
				serialConfig = new SerialConfig();
			}
			txtSerial1.Text = serialConfig.Turbo1;
			txtSerial2.Text = serialConfig.Turbo2;
			txtDetector.Text = serialConfig.Detector;
		}
		catch (Exception)
		{
		}
	}

	protected override void Dispose(bool disposing)
	{
		if (disposing && components != null)
		{
			components.Dispose();
		}
		base.Dispose(disposing);
	}

	private void InitializeComponent()
	{
		this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
		this.btnRefresh = new System.Windows.Forms.Button();
		this.groupBox2 = new System.Windows.Forms.GroupBox();
		this.txtDetector = new System.Windows.Forms.TextBox();
		this.label5 = new System.Windows.Forms.Label();
		this.groupBox1 = new System.Windows.Forms.GroupBox();
		this.txtSerial1 = new System.Windows.Forms.TextBox();
		this.label4 = new System.Windows.Forms.Label();
		this.txtSerial2 = new System.Windows.Forms.TextBox();
		this.label2 = new System.Windows.Forms.Label();
		this.groupBox2.SuspendLayout();
		this.groupBox1.SuspendLayout();
		base.SuspendLayout();
		this.flowLayoutPanel1.Location = new System.Drawing.Point(9, 11);
		this.flowLayoutPanel1.Margin = new System.Windows.Forms.Padding(4);
		this.flowLayoutPanel1.Name = "flowLayoutPanel1";
		this.flowLayoutPanel1.Size = new System.Drawing.Size(341, 452);
		this.flowLayoutPanel1.TabIndex = 0;
		this.btnRefresh.Location = new System.Drawing.Point(627, 338);
		this.btnRefresh.Margin = new System.Windows.Forms.Padding(4);
		this.btnRefresh.Name = "btnRefresh";
		this.btnRefresh.Size = new System.Drawing.Size(129, 61);
		this.btnRefresh.TabIndex = 1;
		this.btnRefresh.Text = "刷新";
		this.btnRefresh.UseVisualStyleBackColor = true;
		this.btnRefresh.Click += new System.EventHandler(btnRefresh_Click);
		this.groupBox2.Controls.Add(this.txtDetector);
		this.groupBox2.Controls.Add(this.label5);
		this.groupBox2.Location = new System.Drawing.Point(387, 184);
		this.groupBox2.Name = "groupBox2";
		this.groupBox2.Size = new System.Drawing.Size(613, 85);
		this.groupBox2.TabIndex = 19;
		this.groupBox2.TabStop = false;
		this.groupBox2.Text = "倍增器";
		this.txtDetector.Location = new System.Drawing.Point(255, 35);
		this.txtDetector.Name = "txtDetector";
		this.txtDetector.ReadOnly = true;
		this.txtDetector.Size = new System.Drawing.Size(296, 25);
		this.txtDetector.TabIndex = 15;
		this.label5.AutoSize = true;
		this.label5.Location = new System.Drawing.Point(38, 38);
		this.label5.Name = "label5";
		this.label5.Size = new System.Drawing.Size(120, 15);
		this.label5.TabIndex = 14;
		this.label5.Text = "倍增器-序列号：";
		this.groupBox1.Controls.Add(this.txtSerial1);
		this.groupBox1.Controls.Add(this.label4);
		this.groupBox1.Controls.Add(this.txtSerial2);
		this.groupBox1.Controls.Add(this.label2);
		this.groupBox1.Location = new System.Drawing.Point(387, 14);
		this.groupBox1.Name = "groupBox1";
		this.groupBox1.Size = new System.Drawing.Size(613, 145);
		this.groupBox1.TabIndex = 20;
		this.groupBox1.TabStop = false;
		this.groupBox1.Text = "分子泵";
		this.txtSerial1.Location = new System.Drawing.Point(255, 56);
		this.txtSerial1.Name = "txtSerial1";
		this.txtSerial1.ReadOnly = true;
		this.txtSerial1.Size = new System.Drawing.Size(296, 25);
		this.txtSerial1.TabIndex = 17;
		this.label4.AutoSize = true;
		this.label4.Location = new System.Drawing.Point(30, 94);
		this.label4.Name = "label4";
		this.label4.Size = new System.Drawing.Size(128, 15);
		this.label4.TabIndex = 16;
		this.label4.Text = "分子泵2-序列号：";
		this.txtSerial2.Location = new System.Drawing.Point(255, 91);
		this.txtSerial2.Name = "txtSerial2";
		this.txtSerial2.ReadOnly = true;
		this.txtSerial2.Size = new System.Drawing.Size(296, 25);
		this.txtSerial2.TabIndex = 15;
		this.label2.AutoSize = true;
		this.label2.Location = new System.Drawing.Point(30, 59);
		this.label2.Name = "label2";
		this.label2.Size = new System.Drawing.Size(128, 15);
		this.label2.TabIndex = 14;
		this.label2.Text = "分子泵1-序列号：";
		base.AutoScaleDimensions = new System.Drawing.SizeF(8f, 15f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.ClientSize = new System.Drawing.Size(1087, 654);
		base.Controls.Add(this.groupBox2);
		base.Controls.Add(this.groupBox1);
		base.Controls.Add(this.btnRefresh);
		base.Controls.Add(this.flowLayoutPanel1);
		base.Margin = new System.Windows.Forms.Padding(4);
		base.Name = "FormVersion";
		this.Text = "版本说明";
		base.Load += new System.EventHandler(FormVersion_Load);
		this.groupBox2.ResumeLayout(false);
		this.groupBox2.PerformLayout();
		this.groupBox1.ResumeLayout(false);
		this.groupBox1.PerformLayout();
		base.ResumeLayout(false);
	}
}
